/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gskorupa.univermon.query;

import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 *
 * @author greg
 */
public class Parser {

    private static volatile Parser instance = new Parser();
    
    String[] keywords={"type", "param1", "param2", "param3", "param4", "status", "date", "value", "ip", "clientname"};
    
    public static Parser getInstance() {
        return instance;
    }

    public String parse(String query) {
        StringTokenizer tokenizer = new StringTokenizer(query, " ",true);
        String element;
        ArrayList elements = new ArrayList();
        while (tokenizer.hasMoreElements()) {
            element = ((String) tokenizer.nextElement()).trim();
            if(!element.isEmpty()){
                if(element.equalsIgnoreCase("AND")){
                    elements.add("&&");
                }else{
                    elements.add(element);
                }
            }
        }
        System.out.println(elements);
        StringBuilder sb=new StringBuilder("");
        for(int i=0; i<elements.size();i++){
            sb.append(elements.get(i));
            sb.append(" ");
        }
        return sb.toString();
    }

}
